package com.jhh.pay.driver.pojo;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import lombok.Data;

@Data
public class PayRequest {
	@JSONField
	private int appId;
	@JSONField
	private float money;
	@JSONField
	private String orderNo;
	@JSONField
	private long orderTime;
	@JSONField
	private boolean activeQuery;
	@JSONField
	private int respTimeout;
	@JSONField
	private boolean async;
	@JSONField
	private String notifyUrl;
	@JSONField
	private String sign;
	
	@JSONField(serializeUsing=ChannelSerializer.class)
	private List<Channel> channels;
	
	@JSONField
	private Map<String, String> extension;
	
	private static class ChannelSerializer implements ObjectSerializer{

		@Override
		public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
				throws IOException {
			JSONObject jo = new JSONObject();
			@SuppressWarnings("unchecked")
			List<Channel> channels = (List<Channel>) object;
			for(Channel c : channels) {
				jo.put(c.getName(), c);
			}
			serializer.write(jo);
		}
		
	}
	
}
